
class BgScene extends egret.DisplayObjectContainer {
	
	private texture: egret.Texture;
	private imgCount:number;
	private bmpArr:egret.Bitmap[] = [];
	
	public constructor() {
		super();
		this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
	}

	private onAddToStage(et: egret.Event) {
		this.removeEventListener(egret.Event.ADDED, this.onAddToStage, this);

		this.texture = RES.getRes("stage01");

		this.imgCount = this.stage.stageHeight / this.texture.textureHeight + 1;

		var originY = this.stage.stageHeight - this.imgCount * this.texture.textureHeight;

		for (var i = 0; i < this.imgCount; i++) {
			var bmp:egret.Bitmap = new egret.Bitmap(this.texture);
			bmp.y = originY + i * this.texture.textureHeight;
			this.addChild(bmp);
			this.bmpArr.push(bmp);
		}

	}

	public startScroll() {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
		this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
	}

	public stopScroll() {
		this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
	}


	private onEnterFrame(et:egret.Event) {
		for (var i = 0; i < this.imgCount; i++) {
			var img: egret.Bitmap = this.bmpArr[i];
			img.y += SettingManager.shareManger().stageScrollSpeed;
			if (img.y > this.stage.stageHeight) {
				img.y = this.bmpArr[0].y - this.texture.textureHeight;
				this.bmpArr.pop();
				this.bmpArr.unshift(img);
			}
		}
	}


}